﻿// Decompiled with JetBrains decompiler
// Type: StoryMode.StoryModePhases.FirstPhase
// Assembly: StoryMode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 11BAE65F-6C15-4628-A9C6-1B968588CDA1
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\StoryMode\bin\Win64_Shipping_Client\StoryMode.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.SceneInformationPopupTypes;
using TaleWorlds.Core;
using TaleWorlds.SaveSystem;

#nullable disable
namespace StoryMode.StoryModePhases
{
  public class FirstPhase
  {
    public const int NeededBannerPieceCount = 3;
    public const int FirstPhaseDurationAsYears = 20;
    public const string FirstBannerPieceStringId = "dragon_banner_center";
    public const string SecondBannerPieceStringId = "dragon_banner_dragonhead";
    public const string ThirdBannerPieceStringId = "dragon_banner_handle";

    internal static void AutoGeneratedStaticCollectObjectsFirstPhase(
      object o,
      List<object> collectedObjects)
    {
      ((FirstPhase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime((object) this.FirstPhaseStartTime, collectedObjects);
    }

    internal static object AutoGeneratedGetMemberValueCollectedBannerPieceCount(object o)
    {
      return (object) ((FirstPhase) o).CollectedBannerPieceCount;
    }

    internal static object AutoGeneratedGetMemberValueFirstPhaseStartTime(object o)
    {
      return (object) ((FirstPhase) o).FirstPhaseStartTime;
    }

    public static FirstPhase Instance => StoryModeManager.Current.MainStoryLine.FirstPhase;

    [SaveableProperty(1)]
    public int CollectedBannerPieceCount { get; private set; }

    [SaveableProperty(2)]
    public CampaignTime FirstPhaseStartTime { get; private set; }

    public CampaignTime FirstPhaseEndTime => CampaignTime.Years(20f) + this.FirstPhaseStartTime;

    public bool AllPiecesCollected => this.CollectedBannerPieceCount == 3;

    public FirstPhase()
    {
      this.CollectedBannerPieceCount = 0;
      this.FirstPhaseStartTime = CampaignTime.Now;
    }

    public void CollectBannerPiece()
    {
      ++this.CollectedBannerPieceCount;
      ItemObject itemObject = (ItemObject) null;
      if (this.CollectedBannerPieceCount == 1)
        itemObject = Campaign.Current.ObjectManager.GetObject<ItemObject>("dragon_banner_center");
      else if (this.CollectedBannerPieceCount == 2)
      {
        itemObject = Campaign.Current.ObjectManager.GetObject<ItemObject>("dragon_banner_dragonhead");
        MBInformationManager.ShowSceneNotification((SceneNotificationData) new FindingSecondBannerPieceSceneNotificationItem(Hero.MainHero));
      }
      else if (this.CollectedBannerPieceCount == 3)
      {
        itemObject = Campaign.Current.ObjectManager.GetObject<ItemObject>("dragon_banner_handle");
        MBInformationManager.ShowSceneNotification((SceneNotificationData) new FindingThirdBannerPieceSceneNotificationItem());
      }
      if (itemObject != null)
        MobileParty.MainParty.ItemRoster.AddToCounts(new EquipmentElement(itemObject, isQuestItem: true), 1);
      StoryModeEvents.Instance.OnBannerPieceCollected();
    }

    public void MergeDragonBanner()
    {
      MobileParty.MainParty.ItemRoster.AddToCounts(new EquipmentElement(Campaign.Current.ObjectManager.GetObject<ItemObject>("dragon_banner_center"), isQuestItem: true), -1);
      MobileParty.MainParty.ItemRoster.AddToCounts(new EquipmentElement(Campaign.Current.ObjectManager.GetObject<ItemObject>("dragon_banner_dragonhead"), isQuestItem: true), -1);
      MobileParty.MainParty.ItemRoster.AddToCounts(new EquipmentElement(Campaign.Current.ObjectManager.GetObject<ItemObject>("dragon_banner_handle"), isQuestItem: true), -1);
      MobileParty.MainParty.ItemRoster.AddToCounts(new EquipmentElement(Campaign.Current.ObjectManager.GetObject<ItemObject>("dragon_banner"), isQuestItem: true), 1);
    }
  }
}
